package com.hdu.dwh.service.impl.model_impl;

import java.util.HashSet;
import java.util.Set;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdu.dwh.mapper.model_mapper.MetaColumnMapper;
import com.hdu.dwh.pojos.model_pojos.MetaColumn;
import com.hdu.dwh.service.model_service.MetaColumnService;

@Service
public class MetaColumnServiceImpl extends ServiceImpl<MetaColumnMapper, MetaColumn> implements MetaColumnService{

    @Override
    public Set<MetaColumn> saveMetaColumns(Set<MetaColumn> columns, Long tableId) {
        Set<MetaColumn> metaColumns = new HashSet<>();
        for (MetaColumn column : columns) {
            MetaColumn metaColumn = new MetaColumn();
            BeanUtils.copyProperties(column, metaColumn);
            // 设置表ID
            metaColumn.setTableId(tableId);

            this.save(metaColumn);

            metaColumns.add(metaColumn);
        }
        return metaColumns;
    }

    @Override
    public MetaColumn findByTableNameAndColumnNameAndModelId(String tableName, String column, Long modelId) {
        MetaColumn metaColumn = this.baseMapper.queryByTableNameAndColumnNameAndModelId(tableName, column, modelId);
        return metaColumn;
    }
}
